<template>
<div>
  <el-form :model="model" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">

    <el-form-item label="班组编号" prop="TypeCode">
      <el-input v-model="model.TypeCode"></el-input>
    </el-form-item>

    <el-form-item label="班组名称" prop="TypeName">
      <el-input v-model="model.TypeName"></el-input>
    </el-form-item>

    <el-form-item label="班组备注" prop="Remark">
      <el-input v-model="model.Remark"></el-input>
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="submitForm">{{ isUpdate?'立即保存': '立即创建'}}</el-button>
      <el-button @click="resetForm">重置</el-button>
    </el-form-item>

  </el-form>
</div>
</template>

<script>
export default {
  props:{
    model:{
      require:true,
      type:Object
    },
    isUpdate:{
      require:true,
      type:Boolean
    }
  },
  data(){
    return{
      rules:{
        TypeCode: {required: true, message: '请输入班组编码', trigger: 'blur'},
        TypeName: {required: true, message: '请输入班组名称', trigger: 'blur'},
      }
    }
  },
  methods:{
    //保存
    submitForm(){
      this.$refs['ruleForm'].validate((valid) => {
        if(valid){
          if(this.isUpdate)
          {
            this.put();
          }else{
            this.add();
          }
        }else{
          this.showNotify('请输入必填项');
          return false;
        }
      });
    },
    resetForm(){
      this.$refs['ruleForm'].resetFields();
    },
    add(){
      this.$http.postForm('/api/TeamType',{model:this.model},{loading:this.$loading()})
      .then((res)=>{
        //回调
        this.$emit('callback');
        this.showNotify('新增班组成功');
      })
    },
    put(){
      this.$http.putForm('/api/TeamType',{model:this.model},{loading:this.$loading()})
      .then(res=>{
        this.$emit('callback');
      })
    },
  }
}
</script>

<style>
</style>